﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace NeuroPrev
{
    public class ControlWriter : TextWriter
    {
        delegate void _WriteCallBack(char value);
        delegate void _WriteCallBack2(string value);
        private Control textbox;
        private Form f;

        public ControlWriter(Control textbox, Form f)
        {
            this.textbox = textbox;
            this.f = f;
        }

        public override void Write(char value)
        {
            _WriteCallBack d = new _WriteCallBack(_Write);
            f.Invoke(d, new object[] { value });
        }
        
        private void _Write(char value)
        {
            textbox.Text += value;
        }

        public override void Write(string value)
        {
            _WriteCallBack2 d = new _WriteCallBack2(_Write);
            f.Invoke(d, new object[] { value });
        }

        private void _Write(string value)
        {
            textbox.Text += value;
        }

        public override Encoding Encoding
        {
            get { return Encoding.ASCII; }
        }
    }
}
